/**
 * Created by wangfei on 2017/6/23.
 */
requirejs.config({
    baseUrl: '../../',
    paths:  {
        avalon: 'javascript/avalon.min',
        jquery: 'js/plugins/jquery/jquery-2.1.1.min',
        navPage: 'nav-page',
        bootstrap: 'js/plugins/bootstrap/bootstrap.min',
        select2: 'js/plugins/select2/select2',
        config: 'javascript/config',
        api: 'javascript/api',
        layer: 'js/plugins/layer1/layer',
        arg: 'javascript/arg',
		ckeditor: 'js/plugins/ckeditor/ckeditor'
    },
    shim: {
        'select2':{
            deps: ['jquery']
        },
        'bootstrap':{
            deps: ['jquery']
        },
        api: {
            deps: ['jquery']
        },
        layer: {
            deps: ['jquery']
        }
    }
});


(function(win, dom, requirejs, initVm){
    var vm;
    requirejs(['avalon', 'jquery', 'navPage','bootstrap','select2', 'config', 'api', 'layer', 'arg', 'ckeditor'], function(){
        //初始化vm
        vm = initVm(dom);
    });
})(window, document, requirejs, function(dom){
    var vm = avalon.define({
        $id:'container',
        currentPage: 'page1',
        images: [],
        changePage: function(page){
            vm.currentPage = page;
        },
		params: {},
		form: {
			id: '',
			categoryId: '',
			categoryIdName: '',
			brandId: '',
			brandName: '',
			barcode: '',
			name: '',
			wareDes: '',
			pricePiece: '',
			priceUnit: '',
			unitId: '',
			unitName: '',
			numberPerBox: '',
			netContent: '',
			weightPiece: '',
			saleSiteId: '',
			saleSiteName: '',
			sendProvinceId: '',
			sendProvinceName: '',
			sendCityId: '',
			sendCityName: '',
			numberWholesale: '',
			numberInventory: '',
			imageMain: '',
			productionLicense: '',
			performStandard: '',
			shelfLife: '',
			methodStorage: '',
			methodPacking: '',
			sizePiece: '',
			dateManufacture: '',
			producingArea: '',
			manufacturer: '',
			description: '',
			wareAttrList: [
				{wareId: '', name: ''}
			],
			wareStockWarn: {
				threshold: '',
				noticeMobile: ''
			}
		},
		wareGet: function(wareId) {
			Api.wareGet({id: wareId}, function(resp) {
				if(resp.code == 0) {
					vm.form = resp.data;
					if(vm.form.wareAttrList.length < 1) {
						vm.form.wareAttrList = [{wareId: vm.form.id, name: ''}];
					}
					vm.images = vm.form.imageMain.split(',');
				} else {
					layer.msg(resp.msg);
				}
			});
		},
		historyBack: function() {
			history.back();
		}
    })
	vm.params = Arg.parse(location.href);
	/*
	CKEDITOR.replace('description', {
		toolbar : 'Basic'
	});
	*/
    avalon.scan(dom.body);
	if(vm.params.id) {
		vm.wareGet(vm.params.id);
	}
    return vm;
});
